package paixu;

import java.util.Arrays;

public class ShellSort {

    public static void main(String[] args) {
        shellSort(new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 });
    }

    public static void shellSort(int[] a) {
        double d1 = a.length;
        int temp = 0;
        while (true) {
            d1 = Math.ceil(d1 / 2);
            int d = (int) d1;
            for (int x = 0; x < d; x++) {
                for (int i = x + d; i < a.length; i += d) {
                    int j = i - d;
                    temp = a[i];
                    for (; j >= 0 && temp < a[j]; j -= d) {
                        a[j + d] = a[j];
                    }
                    a[j + d] = temp;
                }
            }
            if (d == 1)
                break;
        }
        System.out.println(Arrays.toString(a));
    }

}
